package tech.runchen.gz5055.oms.modules.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import tech.runchen.gz5055.oms.common.utils.PageInfo;
import tech.runchen.gz5055.oms.common.utils.Query;
import tech.runchen.gz5055.oms.modules.system.entity.AddressEntity;
import tech.runchen.gz5055.oms.modules.system.mapper.AddressMapper;
import tech.runchen.gz5055.oms.modules.system.service.IAddressService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * <p>
 * 地址信息表 服务实现类
 * </p>
 *
 * @author zzj
 * @since 2023-10-10
 */
@Service
public class AddressServiceImpl extends ServiceImpl<AddressMapper, AddressEntity> implements IAddressService {

    @Override
    public PageInfo queryPage(Map<String, Object> params) {
        Object name = params.get("name");

        IPage<AddressEntity> page = this.page(
                new Query<AddressEntity>().getPage(params),
                new QueryWrapper<AddressEntity>()
                        .like(Objects.nonNull(name), "name", name)
        );

        return new PageInfo(page);
    }

    @Override
    public List<AddressEntity> querySelect(Map<String, Object> params) {
        Object name = params.get("name");

        List<AddressEntity> list = this.list(
                new QueryWrapper<AddressEntity>()
                        .like(Objects.nonNull(name), "name", name)
        );

        return list;
    }

    @Override
    public AddressEntity queryInfoByAddressId(String addressId) {
        AddressEntity address = this.getOne(new QueryWrapper<AddressEntity>().eq("address_id", addressId));
        return address;
    }

    @Override
    public boolean saveAddress(AddressEntity address) {
        return this.save(address);
    }

    @Override
    public boolean updateAddress(AddressEntity address) {
        return this.updateById(address);
    }

    @Override
    public void deleteAddress(Long addressId) {
        this.removeById(addressId);
    }
}
